<?php

// 雪里开简易预约制访客管理系统 V1.0（2025.05.20）
// 演示地址: http://fangke.chalide.cn
// 更新关注: /weivote/yuyuefangke
// 文件路径: inc/head.php
// 文件大小: 1824 字节
// 最后修改时间: 2025-05-20 21:55:38
// 作者: yujianyue
// 邮件: 15058593138@qq.com
// 版权所有,保留发行权和署名权
/**
 * 公共头部文件
 * 功能反馈:15058593138@qq.com
 */

// 检查是否登录
if (!isset($_SESSION['user_id']) && !in_array(get_param('do'), ['login', 'lgout'])) {
    header('Location: ?do=login');
    exit;
}

// 读取网站设置
$db = new MySQLDB();
$settings = [];
$res = $db->getAll("SELECT * FROM `site`");
if ($res) {
    foreach ($res as $item) {
        $settings[$item['skey']] = $item['sval'];
    }
}

// 获取菜单
$userType = isset($_SESSION['user_type']) ? $_SESSION['user_type'] : '';
$menu = isset($menus[$userType]) ? $menus[$userType] : [];
$currentDo = get_param('do', 'login');
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title><?php echo isset($settings['site_name']) ? $settings['site_name'] : '封闭校区访客管理系统'; ?></title>
    <link rel="stylesheet" href="inc/css.css?v=<?php echo $version; ?>">
    <script src="inc/js.js?v=<?php echo $version; ?>"></script>
</head>
<body>
<?php if (isset($_SESSION['user_id']) && !in_array($currentDo, ['login', 'lgout'])): ?>
    <div class="header">
        <div class="header-title"><?php echo isset($settings['site_name']) ? $settings['site_name'] : '封闭校区访客管理系统'; ?></div>
        <div class="header-right">
            <a href="?do=lgout" class="logout-btn">退出</a>
        </div>
    </div>
    
    <?php if (!empty($menu)): ?>
    <div class="navbar">
        <?php foreach ($menu as $item): ?>
        <a href="?do=<?php echo $item['do']; ?>" class="navbar-item <?php echo $currentDo == $item['do'] ? 'active' : ''; ?>">
            <?php echo $item['name']; ?>
        </a>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>
<?php endif; ?>
